import java.util.Deque;
import java.util.LinkedList;
import java.util.Stack;

class MyDueue {

    Deque<Integer> s1;
    Deque<Integer> s2;

        public MyDueue() {
            s1 = new LinkedList<>();
            s2 = new LinkedList<>();
        }

        public void push(int x) {
             s1.push(x);
        }

        public int pop() {
            if(empty()) return -1;

            if(s2.isEmpty()) {
                int size = s1.size();
                while (size != 0) {
                    s2.push(s1.pop());
                    size--;
                }
            }
                return s2.pop();
        }

        public int peek() {
           if(s2.isEmpty()) {
               int size = s1.size();
               while (size != 0) {
                   s2.push(s1.pop());
                   size--;
               }
           }
            return s2.peek();
        }

        public boolean empty() {
            return s1.isEmpty() && s2.isEmpty();
        }
    }

